<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="isComm.jsp"%>
<%@ page import="java.sql.*,database.*" %>
<%
try{
           String stdID = request.getParameter("stdID");
            DBCon db1 = new DBCon();

            int size1 = db1.countChoosedProjects(" ,project,student WHERE project.id = choosedprojects.projectid and choosedprojects.studentId = student.id and choosedprojects.studentId = " + stdID);
            ResultSet res1 = db1.getChoosedProjects(" ,project,student WHERE project.id = choosedprojects.projectid and choosedprojects.studentId = student.id and choosedprojects.studentId = " + stdID+" order by priority");
            String[] id = new String[size1];
            String[] title = new String[size1];
            String[] proj = new String[size1];
            int[] pri = new int[size1];
            for (int i = 0; res1.next(); i++) {
                id[i] = res1.getString("projectid");
                title[i] = res1.getString("project.title");
                proj[i] = res1.getString("student.projId");
                pri[i] = res1.getInt("choosedprojects.priority") + 1;
            }

            int size2 = db1.countProjects(" ,student,choosedprojects where choosedprojects.studentid = student.id and project.id " +
					"= choosedprojects.projectid and project.id = student.projid and student.id = " + stdID);
            ResultSet res2 = db1.getProject("  ,student,choosedprojects where choosedprojects.studentid = student.id and project.id " +
					"= choosedprojects.projectid and project.id = student.projid and student.id = " + stdID);
            String[] id1 = new String[size2];
            String[] title1 = new String[size2];
			int[] pri1 = new int[size2];
            for (int i = 0; res2.next(); i++) {
                id1[i] = res2.getString("project.id");
                title1[i] = res2.getString("project.title");
				pri1[i] = res2.getInt("choosedprojects.priority") + 1;
            }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript" src="js/project.js"></script>
        <script type="text/javascript" src="js/drag_drop.js"></script>
        <link rel="STYLESHEET" href="styles/project.css" type="text/css">
        <link rel="stylesheet" href="styles/control.css" type="text/css"/>
        <link rel="stylesheet" href="styles/stylesheet.css" type="text/css"/>
        <script type="text/javascript">
            var count = <%=size1%>;
            function check() {
                count =0;
                var it = new Array();
                <%
            int x;
            for (x = 0; x < id.length; x++) {
                out.println("it[" + x + "] = document.getElementById('" + id[x] + "');");
            }
            for (; x < id1.length + id.length; x++) {
                out.println("it[" + x + "] = document.getElementById('" + id1[x - id.length] + "');");
            }
%>
    
    for(var i=0;i<it.length;i++)
        {
            if(it[i] != null && it[i].parentNode.id == "DragContainer5")
                {
                    count++;
                }
            }
            var links = parent.document.body.getElementsByTagName("a");
            for(var i=0;i<links.length;i++)
                {
                    links[i].onclick = function() {
                        return confirm("You made changes on choosing project\nDo you want to discard it? if you do not click save changes button");
                    }
                }
                return true;
                
            }
            function save()
            {
                var div = document.getElementById("DragContainer5");
                var showOut = document.getElementById("finalForm");
                var divs = div.getElementsByTagName("div");
                var x = "<form name='finalForm1' id='ff' action='saveAssignedByStud.jsp' method='get'>";
                for(i=0;i<divs.length;i++)
                    {
                        x += "<input type='hidden' name='<%=stdID%>' value='"+ divs[i].id +"'>";
                    }
                    if(divs.length==0)
                        x += "<input type='hidden' name='<%=stdID%>' value=''>";
                    x += "</form>";
                    showOut.innerHTML = x;
                    document.finalForm1.submit();
                }
        </script>
        <%@ include file="IsProff.jsp"%>
				 <style>
			  .DragBox {
				   font-size:15px;
					font-weight: bold;
				   }
			  B.creat
			   {
									   font-size:12px;
					color: blue;
					 font-weight: normal;
				   }
			  B.proj
			   {
									   font-size:12px;
					color: red;
					 					 font-weight: normal;
				   }
					
		  </style>
    <script>
	function openWindow(id)
{
	var images = document.getElementsByTagName("img");
	for(var i=0;i<images.length;i++)
	{
		var width = images[i].width;
		var height = images[i].height;
		if(width > 200)
		images[i].style.width = "200px";
		if(height > 200)
		images[i].style.height = "200px";
	}
	
	var maxX=screen.width; 
	var maxY= screen.height;
	var wX = window.width;
	var wY = window.height;
	var wdth;
	var heght;
	wdth = maxX - (maxX/2);
	heght = maxY - (maxY/2);
	window.open("showProject.jsp?pId="+id,"show"+id,"height="+heght+",width="+wdth+",scrollbars=yes").moveTo((maxX/2)-(wdth/2),(maxY/2)-(heght/2));
	
}
	</script>

</head>
    <body>
        <div id="container">
            <div id="wrapper">
                <div id="content">
                    <center><input type="button" value="save" onclick="save()"></center>
                    <table width="100%"><tr><th><center>Student Choose Project</center></th><th><center>Student Assigned Project</center></th></tr></table></center>
                    <div id='Demo4' width="100%">
                        
                        <DIV class=DragContainer id=DragContainer4 overClass="OverDragContainer">
                            <%
            for (int i = 0; i < id.length; i++) {
                if (proj[i] == null) {
                            %>
                            <DIV class=DragBox id="<%=id[i]%>" overClass="DragBox" dragClass="DragBox" ondblclick="openWindow(<%=id[i]%>)" height="100%">
							<%=title[i]%>
							 <br/><B class='creat'>Priority: </B><b class = 'proj'><%=pri[i]%></b>
							 </DIV>
                            <%
                }
            }
                            %>
                        </DIV>
                        <DIV class=DragContainer id=DragContainer5 overClass="OverDragContainer">
                            <%
            for (int i = 0; i < id1.length; i++) {
                            %>
                            <DIV class=DragBox id="<%=id1[i]%>" projectID = "pr<%=id1[i]%>" overClass="DragBox" dragClass="DragBox" ondblclick="openWindow(<%=id1[i]%>)">
							<%=title1[i]%>
							 <br/><B class='creat'>Priority: </B><b class = 'proj'><%=pri1[i]%></b>							 
							 </DIV>
                            <%
            }
}
catch(Exception e)
{
    //response.sendRedirect("../connectionFailed.jsp?"+e);
    out.println(e);
}
                            %>
                        </DIV>
                        <center><input type="button" value="save" onclick="save()"></center>
                    </div>
                    <div id="finalForm"></div>
                    
                </div>
            <!-- /content --></div>
            <!-- /wrapper -->
            <div class="clear">&nbsp;</div>
        <!-- Important! Fix the problem of height in Firefox --></div>
        <!-- /Container -->

        
    </body>
</html>
